
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Pomelo.EntityFrameworkCore.MySql;
namespace BookShareWebApp
{
    public class BookContext : DbContext
    {

        public DbSet<Book> Book {get;set;}
        public DbSet<User> User {get;set;}

        protected readonly IConfiguration Configuration;

        public BookContext(IConfiguration configuration)
        {
            Configuration = configuration;
        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionString = Configuration.GetConnectionString("WebApiDatabase");
            optionsBuilder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<Book>().ToTable("Book");
            modelBuilder.Entity<User>(
                eb =>{
                    eb.HasNoKey();
                }
            );

          
        }
    }
}